package com.sfh.cpc.home.model;

import com.sfh.cpc.com.entity.ENote;
import com.sfh.cpc.com.entity.ENotify;
import com.sfh.cpc.com.entity.RspBase;
import com.sfh.cpc.com.entity.RspPage;
import com.sfh.cpc.com.req.ReqCityPage;
import com.sfh.cpc.com.req.ReqPageNote;
import com.sfh.cpc.com.req.ReqPageNotify;
import com.sfh.cpc.com.req.ReqRecentlyNote;
import com.sfh.lib.exception.HandleException;
import com.sfh.lib.mvvm.service.BaseViewModel;
import com.sfh.lib.rx.IResult;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/9/17
 */
public class NoticeModel  extends BaseViewModel implements  IResult<RspBase<RspPage<ENote>>>{

    public void page(int nowPage){
        this.execute(new  ReqPageNotify(nowPage), new IResult<RspBase<RspPage<ENotify>>>() {
            @Override
            public void onSuccess(RspBase<RspPage<ENotify>> rspPageRspBase) throws Exception {
                if (rspPageRspBase.success()){
                    setValue("onPageSuccess",rspPageRspBase.getData());
                }else{
                    setValue("onPageSuccess");
                }
            }

            @Override
            public void onFail(HandleException e) {
                setValue("onPageSuccess");
            }
        });

    }
    /***
     * 同城话题
     */
    public void pageCityNote(int nowPage,final String city){
        this.execute(new ReqCityPage(nowPage,city),this);
    }
    /***
     * 综合话题
     */
    public void pageHotNote(int nowPage){

        this.execute(new ReqPageNote(nowPage),this);
    }
    /***
     * 最新话题
     */
    public void pageNewNote(int nowPage){

        this.execute(new ReqRecentlyNote(nowPage),this);
    }
    @Override
    public void onSuccess(RspBase<RspPage<ENote>> data) throws Exception {
        if (data.success()){
            this.setValue("onPageSuccess",data.getData());
        }else{
            this.showToast(data.getMsg());
            this.setValue("onPageSuccess");
        }
    }

    @Override
    public void onFail(HandleException e) {
        showToast(e.getMsg());
        this.setValue("onPageSuccess");
    }
}
